package com.src.computec.radar.consultas.ordenproceso.listener;
import com.src.computec.radar.consultas.base.constantes.ConstantesGenerales;
import com.src.log4j.logger.custom.XLogger;
import java.io.File;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 *
 * @author fsanchez
 */
public class ContextListener implements ServletContextListener {
    
    private static XLogger xLogger;
    
  /**
     * ### Method from ServletContextListener ###
     * 
     * Called when a Web application is first ready to process requests
     * (i.e. on Web server startup and when a context is added or reloaded).
     * 
     * For example, here might be database connections established
     * and added to the servlet context attributes.
     * @param evt 
     */
    public void contextInitialized(ServletContextEvent evt) {
        this.xLogger = (XLogger) XLogger.getLogger(this.getClass().getName());
        xLogger.info("ContextListener:contextInitialized");
        ConstantesGenerales constantes = ConstantesGenerales.getInstance();
        String directorio_ = ConstantesGenerales.FULL_PATH_GRAFICAS;
        File dir_ = new File(directorio_);
        if (dir_.isDirectory()) {
            String[] listFiles_ = dir_.list();
            for (int i=0; i<listFiles_.length; ++i) {
                File tmpFile = new File(directorio_ + "/" + listFiles_[i]);
                tmpFile.delete();
            }
        }
    }

    /**
     * ### Method from ServletContextListener ###
     * 
     * Called when a Web application is about to be shut down
     * (i.e. on Web server shutdown or when a context is removed or reloaded).
     * Request handling will be stopped before this method is called.
     * 
     * For example, the database connections can be closed here.
     */
    public void contextDestroyed(ServletContextEvent evt) {        
    }
}